<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUsersTable extends Migration {

	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		Schema::create('users', function($table){
			$table->increments('pk');

			$table->string('id')->unique();
			$table->string('password');
			$table->string('name');
			$table->string('first_lastname');
			$table->string('second_lastname');
			$table->date('date_of_birth');

			$table->string('address');
			$table->string('email')->unique();
			$table->string('phone');
			

			$table->boolean('password_changed');
			$table->boolean('active_user');
			$table->integer('created_by_fk')->unsigned(); //The user who created this user
			$table->integer('user_type_fk')->unsigned();
			$table->rememberToken();
			$table->timestamps();

		});

		Schema::table('users', function($table){
			$table->foreign('user_type_fk')->references('pk')->on('user_types');
		});
	}

	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
		Schema::table('users', function($table){
			$table->dropForeign('users_user_type_fk_foreign');
		});
		echo "users table relationships removed\n";
		Schema::drop('users');
		echo "users table deleted\n";
	}

}
